001    /*
002     * Copyright 2005 Stephen J. McConnell
003     *
004     * Licensed  under the  Apache License,  Version 2.0  (the "License");
005     * you may not use  this file  except in  compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *   http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed  under the  License is distributed on an "AS IS" BASIS,
012     * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
013     * implied.
014     *
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package net.dpml.tools.info;
020    
021    import java.util.Arrays;
022    import java.util.Properties;
023    
024    import net.dpml.library.info.AbstractDirective;
025    
026    import net.dpml.lang.UnknownKeyException;
027    
028    /**
029     * The BuilderDirective class describes the configuration of the build system.
030     *
031     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
032     * @version 1.1.0
033     */
034    public final class BuilderDirective extends AbstractDirective
035    {
036        private final ListenerDirective[] m_listeners;
037        private final String m_phase;
038        
039       /**
040        * Creation of a new library directive.
041        * @param listeners an array of listener directives
042        * @param phase the default target phase
043        * @param properties supplimentary properties
044        * @exception UnknownKeyException if a unknown key is referenced
045        */
046        public BuilderDirective( 
047          ListenerDirective[] listeners, String phase, Properties properties ) throws UnknownKeyException
048        {
049            super( properties );
050            
051            if( null == listeners )
052            {
053                throw new NullPointerException( "listeners" );
054            }
055            if( null == phase )
056            {
057                throw new NullPointerException( "phase" );
058            }
059            for( int i=0; i<listeners.length; i++ )
060            {
061                if( null == listeners[i] )
062                {
063                    throw new NullPointerException( "listener" );
064                } 
065            }
066            
067            m_phase = phase;
068            m_listeners = listeners;
069        }
070        
071       /**
072        * Return the set of listener directives.
073        * @return the listener directive array
074        */
075        public ListenerDirective[] getListenerDirectives()
076        {
077            return m_listeners;
078        }
079        
080       /**
081        * Return the default phase.
082        * @return the default phase name.
083        */
084        public String getDefaultPhase()
085        {
086            return m_phase;
087        }
088        
089       /**
090        * Compare this object with another for equality.
091        * @param other the other object
092        * @return true if equal
093        */
094        public boolean equals( Object other )
095        {
096            if( super.equals( other ) && ( other instanceof BuilderDirective ) )
097            {
098                BuilderDirective object = (BuilderDirective) other;
099                if( !equals( m_phase, object.m_phase ) )
100                {
101                    return false;
102                }
103                else
104                {
105                    return Arrays.equals( m_listeners, object.m_listeners );
106                }
107            }
108            else
109            {
110                return false;
111            }
112        }
113        
114       /**
115        * Compute the hash code value.
116        * @return the hash value
117        */
118        public int hashCode()
119        {
120            int hash = super.hashCode();
121            hash ^= super.hashValue( m_phase );
122            hash ^= super.hashArray( m_listeners );
123            return hash;
124        }
125    }